package org.cosmact.common.utils;

import java.util.Collection;

/**
 * Common utilies
 * 
 *@author hsieh 234aini@gmail.com
 * 
 */
public class Utilities {

    /**
     * Test the given string is null or empty
     * 
     * @param dest
     * @return
     */
    public static boolean isNullOrEmpty(String dest) {
	return dest == null || dest.equals("");
    }

    /**
     * Check the given collection is null or empty
     * 
     * @param col
     * @return
     */
    public static boolean isNullOrEmpty(Collection<?> col) {
	return col == null || col.isEmpty();
    }

    public static int getLocationForMaxValue(int[] source) {
	if (source == null || source.length <= 0)
	    return -1;
	if (source.length == 1) {
	    return 0;
	}
	int location = 0;
	int value = source[location];
	for (int i = 1; i < source.length; i++) {
	    if (source[i] > value) {
		location = i;
		value = source[i];
	    }
	}
	return location;
    }

    public static int getLocationForMinValue(int[] source) {
	if (source == null || source.length <= 0)
	    return -1;
	if (source.length == 1) {
	    return 0;
	}
	int location = 0;
	int value = source[location];
	for (int i = 1; i < source.length; i++) {
	    if (source[i] < value) {
		location = i;
		value = source[i];
	    }
	}
	return location;
    }
}
